package imageviewerdb;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ImageDb{
    
    private String path;
    private String topic;
    private String size;
    private String extension;
    private String description;
    private String name;
    private boolean confidentiality;
    private Image thumbnail;
    private int width = 100;
    private int height = 100;
                    
    public ImageDb() {}
    
    public ImageDb(String path, String topic, String size, String extension, String description, String name, boolean confidentiality) {        
        this.confidentiality = confidentiality;
        this.description = description;
        this.name = name;
        this.path = path;
        this.size = size;
        this.topic = topic;
        this.extension = extension;
    }
    
    // gets & sets
    public String getPath() {return this.path;}
    public String getTopic() {return this.topic;}
    public String getSize() {return this.size;}
    public String getExtension() {return this.extension;}
    public String getDescription() {return this.description;}
    public String getName() {return this.name;}
    public boolean getConfidentiality() { return this.confidentiality; }
    
    public void setPath(String path) { this.path = path;}
    public void setTopic(String topic) { this.topic = topic;}
    public void setSize(String size) { this.size = size;}
    public void setExtension(String extension) { this.extension = extension;}
    public void setDescription(String description) { this.description = description;}
    public void setName(String name) { this.name = name;}
    public void setConfidentiality(boolean confidentiality) { this.confidentiality = confidentiality; }

    public void setThumbHeight(int height) {
        this.height = height;
    }

    public void seThumbtWidth(int width) {
        this.width = width;
    }
        
    public Image getThumbnail()
    {
    	if(thumbnail != null) {            
            return thumbnail;
    	}
    	else{
            Image img = null;
            try {
                img = ImageIO.read( new File(path) );
            } catch(IOException e) {                
                e.printStackTrace();
            }
            BufferedImage th = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D g2d = th.createGraphics();
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            //g2d.setColor(Color.black);
            g2d.setColor(new Color(0, 0, 0, 0));
            g2d.fillRect(0, 0, width, height);
            if(img != null)
                g2d.drawImage(img, 0, 0, width, height, null);
            g2d.dispose();            
            thumbnail = th;
            return thumbnail;
    	}
    }
}